<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box">

    </div>
    <script>
        var targetDate = new Date("2022/12/24")
        // console.log(targetDate-currentDate)   //时间戳差值
        function Time1(current, target) {
            var sub = Math.ceil((target - current) / 1000)
            // console.log(sub)
            var day = parseInt(sub / (60 * 60 * 24))
            // console.log(day)
            var hours = parseInt(sub % (60 * 60 * 24) / (60 * 60))
            // console.log(hours)
            var minutes = parseInt(sub % (60 * 60) / 60)
            var seconds = sub % 60
            var obj = {
                day: day,
                hours: hours,
                minutes: minutes,
                seconds: seconds
            }
            return obj
        }
        //间隔定时器
        setInterval(function(){
            var currentDate = new Date()
            var res = Time1(currentDate, targetDate)
            // document.write(`距离9月1号时间:${res.day}天${res.hours}小时${res.minutes}分${res.seconds}秒`)
            // document.write("<br>")
            box.innerHTML=`距离考试时间约:${res.day}天${res.hours}小时${res.minutes}分${res.seconds}秒`
        },1000)
    </script>
</body>

</html>